package com.sskj.qiangjin.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.qiangjin.R;
import com.sskj.qiangjin.bean.CommonBean;
import com.sskj.qiangjin.bean.HelpCenterBean;
import com.sskj.qiangjin.presenter.UserAgreementPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.APP_USER_AGREEMENT)//用户协议
public class UserAgreementActivity extends BaseActivity<UserAgreementPresenter> {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private SlimAdapter slimAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.app_activity_user_agreement;
    }

    @Override
    public UserAgreementPresenter getPresenter() {
        return new UserAgreementPresenter();
    }

    @Override
    protected void initView() {
        setTitle("用户协议");

        mPresenter.getCommonData();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        slimAdapter = SlimAdapter.create().register(R.layout.app_recy_item_help_center, new SlimInjector<HelpCenterBean>() {
            @Override
            public void onInject(HelpCenterBean data, IViewInjector injector, List payloads) {
                injector
                        .text(R.id.tvTitle, data.getTitle())
                        .text(R.id.tvContent, data.getContent())
                ;
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
    }


    public void updataUI(CommonBean commonBean) {
        CommonBean.ProxyInfoBean proxy_info = commonBean.getProxy_info();
        List<CommonBean.ProxyInfoBean.TermsBean> terms = proxy_info.getTerms();
        ArrayList<HelpCenterBean> helpCenterBeans = new ArrayList<>();
        for (int i = 0; i < terms.size(); i++) {
            HelpCenterBean helpCenterBean = new HelpCenterBean();
            helpCenterBean.setTitle(terms.get(i).getTitle());
            helpCenterBean.setContent(terms.get(i).getContent());
            helpCenterBeans.add(helpCenterBean);
        }
        slimAdapter.updateData(helpCenterBeans);
    }

}
